<?php

class Technical_OrderController extends Zend_Controller_Action
{

    public function init(){  
    }
    
    public function indexAction(){
    	    	$session = new Zend_Session_Namespace('identity');
		$form = new Application_Form_Classes();
		$form->appendValidationEngineFiles($this->view);
		$polish = BH_TranslatePL::getPolishTranslation();
		$translate = new Zend_Translate('array', $polish, 'pl');
		$form->setTranslator($translate);
		//$form->getElement('typeForm')->setValue('addform');
		$form->submit->setLabel('Dodaj nowe zajęcia');
		$this->view->ClassesForm = $form;
    	
    }
    
    public function addclassesAction(){
    	$session = new Zend_Session_Namespace('identity');
		$form = new Application_Form_Classes();
		$form->appendValidationEngineFiles($this->view);
		$polish = BH_TranslatePL::getPolishTranslation();
		$translate = new Zend_Translate('array', $polish, 'pl');
		$form->setTranslator($translate);
		//$form->getElement('typeForm')->setValue('addform');
		$form->submit->setLabel('Dodaj nowe zajęcia');
		$this->view->ClassesForm = $form;
    	
    }
    
    
    
    public function getAction(){
  /*  	
    	$session = new Zend_Session_Namespace('identity');
		$form = new Application_Form_Classes();
		$form->appendValidationEngineFiles($this->view);
		$polish = BH_TranslatePL::getPolishTranslation();
		$translate = new Zend_Translate('array', $polish, 'pl');
		$form->setTranslator($translate);
		//$form->getElement('typeForm')->setValue('addform');
		//$form->submit->setLabel('Dodaj nowe zajęcie');
		$this->view->ClassesForm = $form;
  */
    	$request = $this->getRequest();
    	if ($request->isPost()) {
    		$orderParam = $request->getPost('orderparam');
    		if($orderParam == 'lecturer') {
    			$lecturerDao = new Application_Model_Dao_User();
    			$lecturers = $lecturerDao->getToSelectLecturers();
    			echo json_encode($lecturers);
    		} else if ($orderParam == 'course') {
    			$coursesTypeDao = new Application_Model_Dao_CoursesType();
  				$coursesTypes = $coursesTypeDao->getToSelectClasses();
  				echo json_encode($coursesTypes);
    		}
    	}
    }
    
    public function addAction() {

		$yearDao = new Application_Model_Dao_YearsStudent();
  		$years = $yearDao->getToSelectInformationAboutYear();
  		$this->view->years = $years;

    	$subjectDao = new Application_Model_Dao_Subject();
  		$subjects = $subjectDao->getToSelect();
    	$this->view->subjects = $subjects;
    	
    	
    	$coursesTypeDao = new Application_Model_Dao_CoursesType();
  		$coursesTypes = $coursesTypeDao->getToSelect();
    	$this->view->coursesTypes = $coursesTypes;
  		
//    	$formSubject = new Application_Form_Subject();
//		$formSubject->appendValidationEngineFiles($this->view);
//		$polish = BH_TranslatePL::getPolishTranslation();
//		$translate = new Zend_Translate('array', $polish, 'pl');
//		$formSubject->setTranslator($translate);
//			
//		$formSubject->submit->setLabel('Dodaj nowy przedmiot');
//		$this->view->SubjectForm = $formSubject;
//		$requestSubject = $this->getRequest();
//		if ($requestSubject->isPost()) {
//			if ($formSubject->isValid($requestSubject->getPost())) {
//				$subject = new Application_Model_Entities_Subject();
//				$subject->setDesignation( $formSubject->getValue('designation'));
//				$subject->setShort( $formSubject->getValue('short'));
//				$subjectDao = new Application_Model_Dao_Subject();
//				$subjectDao->saveSubject($subject);
//
//				$this->_helper->redirector('add');
//			}
//		}
    	
		
//		$formOrder = new Application_Form_Order();
//		$formOrder->appendValidationEngineFiles($this->view);
//		$polish = BH_TranslatePL::getPolishTranslation();
//		$translate = new Zend_Translate('array', $polish, 'pl');
//		$formOrder->setTranslator($translate);
//		
//    	$formOrder->submit->setLabel('Zapisz');
//		$this->view->OrderForm = $formOrder;
    	
    	$requestOrder = $this->getRequest();
    	if ($this->_request->isPost()) {
    		
//    		if ($formOrder->isValid($requestOrder->getPost())) {
    			$order = new Application_Model_Entities_Order();
    			$orderParticulary = new Application_Model_Entities_ParticularyOrder();
//    			$order->setYear( $this->_request->getPost('yearStudentsid') );
    			$order->setSubject( $this->_request->getPost('subjectid') );
    			$order->setDimensionSemester( $this->_request->getPost('numberHourPerSemester') );
    			
    			
				$orderParticulary->setSemester( $this->_request->getPost('') );
				$orderParticulary->setSubject( $this->_request->getPost('subjectid') );  // do usuniecia
				$orderParticulary->setCourseType( $this->_request->getPost('coursesTypeid-1') );	// 1-wyklad, 2-cwiczenia
				$orderParticulary->setExamType( $this->_request->getPost('coursesTypeid-1-examType') );
//				$orderParticulary->setHoursTotal( $this->_request->getPost('coursesTypeid-1-hoursTotal') ); //brak
				$orderParticulary->setYearStudentsGroup( $this->_request->getPost('coursesTypeid-1-numberGroups') );    			
//    			$orderParticulary->set( $this->_request->getPost('coursesTypeid-1-lecturer') );
//    			$orderParticulary->set( $this->_request->getPost('coursesTypeid-1-numberGroups') );
//    			$orderParticulary->set( $this->_request->getPost('group-coursesTypeid-1-1') );
//    			$orderParticulary->set( $this->_request->getPost('lecturer-coursesTypeid-1-1') );
//    			$orderParticulary->setNumberWeek( $this->_request->getPost('coursesTypeid-1-PerWeek') );
//    			$orderParticulary->setDimensionSemester( $this->_request->getPost('coursesTypeid-1-PerSemester') );
				
				    
//    			$order->set( $this->_request->getPost('') );
//    			
//    			$order->setSpeciality( $this->_request->getPost('specialityID') );
//    			$order->setNumberWeek( $this->_request->getPost('numberWeek') );
//    			$order->setDimensionSemester( $this->_request->getPost('dimensionSemester') );
//    			$order->setHourYear( $this->_request->getPost('hourYear') );
//    			$order->setHourSemester( $this->_request->getPost('hourSemester') );
//    			$order->setYear( $this->_request->getPost('yearID') );
    			$orderDao = new Application_Model_Dao_Order();
//    			$orderDao->saveOrder($order);
//  				$result = Zend_Auth::getInstance()->authenticate($order);
//				if ($result->isValid()) {
//					$form->login->addError('xfs '.$order);
//    				$this->_helper->redirector('index');
//    			} else {
//    				$this->_request->login->addError('Należy wypełnić wszystkie pola.');
//    			}
    		//}
//    	}
    	}    
    
    }
}